package com.fcy.dialog.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.fcy.dialog.R;

import java.util.Arrays;
import java.util.List;

/**
 * 用于填充CommonDialogList的ListView的数据
 */
public class DialogItemAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<String> data;

    public DialogItemAdapter(Context context, List<String> data) {
        inflater = LayoutInflater.from(context);
        this.data = data;
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_dialog, parent, false);
            holder = new ViewHolder();
            holder.textItem = (TextView) convertView.findViewById(R.id.text_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textItem.setText(data.get(position));
        return convertView;
    }

    private static class ViewHolder {
        public TextView textItem;
    }
}
